import { Component, OnInit, HostBinding } from "@angular/core";

import { GamesService } from "../../services/games.service";
import { Game } from "src/app/models/Game";

@Component({
  selector: "app-games-list",
  templateUrl: "./games-list.component.html",
  styleUrls: ["./games-list.component.css"]
})
export class GamesListComponent implements OnInit {
  @HostBinding("class") classes = "row";

  games: any = [];

  constructor(private gameService: GamesService) {}

  ngOnInit() {
    this.getGames();
  }

  getGames() {
    this.gameService.getGames().subscribe(
      res => {
        this.games = res;
      },
      err => console.error(err)
    );
  }

  deleteGame(id: string) {
    this.gameService.deleteGame(id).subscribe(
      res => {
        console.log(res);
        this.getGames();
      },
      err => console.error(err)
    );
  }
}
